package com.ckd.flyingtrip.utils;

import android.content.Context;
import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.baidu.mapapi.model.LatLng;
import com.ckd.flyingtrip.constants.Constants;
import com.ckd.flyingtrip.javabean.CityBean;
import com.ckd.flyingtrip.widge.SingleVolleyRequestQueue;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class TextUtils {

    /*全部接口*/
    public static void all(Context context) {
        getsitelist_xcx(context);
        getmeallist_xcx(context);
        sendMessage_xcx(context);
        order_xcx(context);
        appletspay(context);
        chargeStartNotify(context);
        chargeEndNotify(context);
        getChargeRecordList(context);
        takeBattery(context);
    }

    /*充电柜列表接口*/
    public static void getsitelist_xcx(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/getsitelist_xcx.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("充电柜列表接口", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("longitude", "123.490125");
                    json_url.put("latitude", "41.703792");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));

                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }

    /*缴费套餐列表*/
    public static void getmeallist_xcx(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/getmeallist_xcx.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("缴费套餐列表", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("userId", "118b149fad8c49909e3a4ca84ab257a5");
                    json_url.put("userArea", "210100");
                    json_url.put("cabinet", "CDZD08KXHD190401298");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));
                Log.e("缴费套餐列表", map.toString());
                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }

    /*充满电通知骑手发送短信接口*/
    public static void sendMessage_xcx(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/sendMessage_xcx.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("充满电通知骑手发送短信接口", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("userId", "118b149fad8c49909e3a4ca84ab257a5");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));
                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }

    /*判断是否有未完成订单接口 （最新的一条记录）*/
    public static void order_xcx(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/order_xcx.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("判断是否有未完成订单接口 （最新的一条记录）", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("userId", "118b149fad8c49909e3a4ca84ab257a5");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));
                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }

    /*微信小程序支付接口*/
    public static void appletspay(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/appletsPay_XCX.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("微信小程序支付接口", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("userId", "118b149fad8c49909e3a4ca84ab257a5");
                    json_url.put("userArea", "210100");
                    json_url.put("batteryType", "0");
                    json_url.put("batteryV", "48");
                    json_url.put("batteryT", "1");
                    json_url.put("code", "021tu6000UlLxK1DaK300bOD9b2tu60e");
                    json_url.put("costId", "1");
                    json_url.put("cabinetId", "123456");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));
                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }

    /*业务回调接口：开始充电*/
    public static void chargeStartNotify(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/chargeStartNotify.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("业务回调接口：开始充电", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("userId", "118b149fad8c49909e3a4ca84ab257a5");
                    json_url.put("deviceId", "123456");
                    json_url.put("doorId", "1");
                    json_url.put("orderId", "123456");
                    json_url.put("startTime", "2020-10-20 09:00:00");
                    json_url.put("closeTime", "2020-10-20 10:00:00");
                    json_url.put("batteryType", "0");
                    json_url.put("batteryV", "48");
                    json_url.put("batteryT", "1");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));
                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }

    /*业务回调接口：充电结束取走电池*/
    public static void chargeEndNotify(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/chargeEndNotify.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("业务回调接口：充电结束取走电池", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("userId", "118b149fad8c49909e3a4ca84ab257a5");
                    json_url.put("deviceId", "123456");
                    json_url.put("doorId", "1");
                    json_url.put("orderId", "123456");
                    json_url.put("endTime", "2020-10-20 10:00:00");
                    json_url.put("popTime", "2020-10-20 10:05:00");
                    json_url.put("closeTime", "2020-10-20 10:10:00");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));
                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }

    /*订单/充电记录接口列表*/
    public static void getChargeRecordList(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/getChargeRecordList.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("订单/充电记录接口列表", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("userId", "118b149fad8c49909e3a4ca84ab257a5");
                    json_url.put("page", "1");
                    json_url.put("row", "10");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));
                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }

    /*取电池接口*/
    public static void takeBattery(Context context) {
        StringRequest request = new StringRequest(Request.Method.POST, "https://travel.ckdhd.com/rentcar/takeBattery.action", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                Log.e("取电池接口", s);
                try {
                    JSONObject json = new JSONObject(s);
                    String code = json.getString("code");


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject json_url = new JSONObject();
                try {
                    json_url.put("userId", "118b149fad8c49909e3a4ca84ab257a5");
                    json_url.put("cabinet", "123456");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                map.put("inputParameter", DataCheck.signCheck(json_url.toString()));
                return map;
            }
        };
        SingleVolleyRequestQueue.getInstance(context).addToRequestQueue(request);
    }
}
